import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.ImageIcon;

public class Projectile implements GameObject{
	private int x, y, xSpeed, ySpeed, width, height, type;
	private Image sprite;
	private boolean exists;
	private ArrayList collisionListCollection;
	
	public Projectile(int x, int y, int type, int xSpeed, int ySpeed, String spritePath, ArrayList collisionListCollection) {
		this.x = x;
		this.y = y;
		this.type = type;
		this.xSpeed = xSpeed;
		this.ySpeed = ySpeed;
		this.collisionListCollection = collisionListCollection;
		exists = true;

		ImageIcon ii = new ImageIcon(this.getClass().getResource(spritePath));
		sprite = ii.getImage();

		width = sprite.getWidth(null);
		height = sprite.getHeight(null);
	}

	public boolean exists(){
		return exists;
	}

	public void draw(Graphics2D g2d, Game observer) {
		g2d.drawImage(sprite, x, y, observer);
	}
	
	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getXSpeed() {
		return xSpeed;
	}

	public int getYSpeed() {
		return ySpeed;
	}

	public Image getSprite() {
		return sprite;
	}

	public void move() {
		x += xSpeed;
		y += ySpeed;
		
		collision();
	}

	private void collision() {
		Rectangle objRect = new Rectangle(x, y, width, height);
		for (int i = 0; i < collisionListCollection.size(); i++){
			ArrayList objects = (ArrayList) collisionListCollection.get(i);
			for (int j = 0; j < objects.size(); j++){
				GameObject tObject = (GameObject) objects.get(j);
				Rectangle tObjRect = new Rectangle(tObject.getX(), tObject.getY(), tObject.getWidth(), tObject.getHeight());
				
				if (objRect.intersects(tObjRect)){
					if (tObject.projectileCollision(type) == -1){
						exists = false;
					}
				}
			}
		}
	}


	@Override
	public int getWidth() {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public int getHeight() {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public int getType() {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public void specialFunction(int type) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public int projectileCollision(int type) {
		// TODO Auto-generated method stub
		return 0;
	}
}
